const state = {
  debug: false,
  originMap: {},
  dataStatusMap: {},
  fieldStatusMap: {}
};
const getters = {};
const mutations = {
  enableDebug(state) {
    state.debug = true;
  },
  stopDebug(state) {
    console.log("entry stopDebug");
    state.debug = false;
  },
  SET_ORIGIN(state, { comId, data }) {
    for (const [keyName, value] of Object.entries(data)) {
      if (state.originMap[comId]) {
        state.originMap[comId][keyName] = value;
      } else {
        state.originMap[comId] = { [keyName]: value };
      }
    }
  },
  SET_DATA_STATUS(state, { comId, data }) {
    for (const [keyName, value] of Object.entries(data)) {
      if (state.dataStatusMap[comId]) {
        state.dataStatusMap[comId][keyName] = value;
      } else {
        state.dataStatusMap[comId] = { [keyName]: value };
      }
    }
  },
  SET_FIELD_STATUS(state, { comId, fields }) {
    for (const [keyName, value] of Object.entries(fields)) {
      if (state.fieldStatusMap[comId]) {
        state.fieldStatusMap[comId][keyName] = value;
      } else {
        state.fieldStatusMap[comId] = { [keyName]: value };
      }
    }
  },
};
const actions = {
  async setOrigin(state, { comId, data }) {
    if (state.debug) {
      state.commit("SET_ORIGIN", { comId, data });
    }
  },
  async setDataStatus(state, { comId, data }) {
    if (state.debug) {
      state.commit("SET_DATA_STATUS", { comId, data });
    }
  },
  async setFieldStatus(state, { comId, data }) {
    if (state.debug) {
      state.commit("SET_FIELD_STATUS", { comId, data });
    }
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions
};
